package com.hey.baseapplication.model;

import android.util.Log;

import com.hey.baseapplication.api.ApiService;
import com.hey.baseapplication.api.DataListener;
import com.hey.baseapplication.api.RetrofitClient;
import com.hey.baseapplication.bean.Event;
import com.hey.baseapplication.bean.EventApi;
import com.hey.baseapplication.bean.Response;

import java.util.List;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Hey on 17/1/3.
 */

public class IMFModel implements BaseModel {

    public Subscription getData(EventApi eventApi, final DataListener<List<Event>> listener){

        return RetrofitClient.getInstance().getEventList(ApiService.ACCESS_TOKEN,"0").subscribeOn(Schedulers.newThread()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<Response<List<Event>>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                e.printStackTrace();
            }

            @Override
            public void onNext(Response<List<Event>> listResponse) {
                if (listResponse.getCode()==40000){
                    Log.e("IMF",listResponse.getData().toString());
                    listener.onSuccess(listResponse.getData());
                }else{
                    Log.e("IMF",listResponse.getMsg());
                }
            }
        });
    }

}
